<template>
  <base-breadcrumb :breadcrumb="!isAudit">
    <a-card>
      <title-name title="推荐分包商信息"></title-name>
      <a-form-model  :model="form" ref="ruleForm" 
          :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
          :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
        <a-row>
          <a-col :md="12" :sm="12">
            <a-form-model-item
                    label="推荐分包商"
                    :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                    :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
              <BaseInput v-model="form.recommendSubcontractors" :disabled="type=='view'||type=='approve' || isConsultation" placeholder="请输入" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :md="24" :sm="24">
            <a-form-model-item
                    label="分包商类型"
                    :labelCol="{ lg: { span: 3 }, sm: { span: 3 } }"
                    :wrapperCol="{ lg: { span: 21 }, sm: { span: 21 } }">
              <a-tree-select :disabled="type=='view'||type=='approve'|| isConsultation"
                v-model="form.list"
                style="width: 100%;"
                multiple
                :dropdown-style="{ maxHeight: '500px', overflow: 'auto' }"
                :replace-fields="{children:'children', key:'id', value: 'id', title: 'name'}"
                :tree-data="invesList"
                placeholder="请选择" >
              </a-tree-select>
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :md="24" :sm="24">
            <a-form-model-item label="推荐承诺：" style="display:flex"
                         :labelCol="{ lg: { span: 3 }, sm: { span: 3 } }"
                         :wrapperCol="{ lg: { span: 21 }, sm: { span: 21 } }">
              本人推荐该公司参加
              <a-select  v-model="form.branchCompanyId" id="selectbranch" :disabled="type=='view'||type=='approve' || isConsultation"  @change="changeBranchCompany">
              <a-select-option v-for="item in companyList" :key="item.id" :value="item.id">{{item.name}}</a-select-option>
            </a-select>
              单位
                  <a-select id="selectbranch"  v-model="form.project" :disabled="type=='view'||type=='approve' || isConsultation" >
                    <a-select-option v-for="item in projectList" :key="item.code" :value="item.code">{{item.name}}
                    </a-select-option>
                  </a-select>
              项目
              <BaseInput id="selectbranch" :disabled="type=='view'||type=='approve' || isConsultation" v-model="form.cooperation"  placeholder="请输入"/>标的物品名） 招标/议标采购。如果出现供货（或工程）质量、供货（或工程）延期、冒牌、弄虚作假.....等有关问题，本人协调处理。
              
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col>
            <a-form-model-item label="推荐理由：" style="display:flex"
                         :labelCol="{lg: {span: 3}, sm: {span:3}}"
                         :wrapperCol="{lg: {span: 21}, sm: {span: 21} }">
              <BaseTextarea :disabled="type=='view'||type=='approve' || isConsultation"   v-model="form.recommendInformation"  placeholder="请输入"/>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
      
      <title-name title="推荐人信息"></title-name>
      <a-form-model :model="form.recommendInfo" >
        <a-row :gutter="24">
          <a-col :md="12" :sm="12">
          
            <a-form-model-item label="推荐人："
                         :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                         :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
              <BaseInput v-model="form.recommendInfo.referrer"  disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :md="12" :sm="12">
            <a-form-model-item label="年龄："
                         :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                         :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
              <BaseInput v-model="form.recommendInfo.age"  disabled/>
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :md="12" :sm="12">
            <a-form-model-item  label="身份证号："
                         :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                         :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
              <BaseInput  v-model="form.recommendInfo.idNum"  disabled/>
            </a-form-model-item>
          </a-col>
            <a-col :md="12" :sm="12">
            <a-form-model-item   label="政治面貌："
                         :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                         :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
              <BaseInput v-model="form.recommendInfo.politicalFace"  disabled/>
            </a-form-model-item>
            </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :md="12" :sm="12">
            <a-form-model-item   label="单位："
                         :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                         :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
              <BaseInput  v-model="form.recommendInfo.unitName" disabled/>
            </a-form-model-item>
          </a-col>
            <a-col :md="12" :sm="12">
            <a-form-model-item   label="职位："
                         :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                         :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
              <BaseInput v-model="form.recommendInfo.position"  disabled/>
            </a-form-model-item>
            </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :md="12" :sm="12">
            <a-form-model-item label="联系方式："
                         :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                         :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
              <BaseInput v-model="form.recommendInfo.tel"  disabled/>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
  
      <!-- <title-name title="推荐人签字"></title-name>
      <a-form>
        <a-row :gutter="24">
          <a-col :sm="12" :md="12" >
            <a-form-model-item label="签字编码"
                         :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                         :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
              <BaseInput :disabled="type=='view'" placeholder="请输入编码" v-model="form.signCode"></BaseInput>
            </a-form-model-item>
          </a-col>
          <a-col  :sm="3" :md="3">
            <a-button :disabled="type=='view'" type="primary" style="margin:0 10px">确定签字</a-button>
          </a-col>
          <a-col  :sm="6" :md="6">
          <BaseInput type="textarea"></BaseInput>
          </a-col>
        </a-row>
      </a-form> -->

    </a-card>

    <div v-if="!isConsultation" style="float:right;margin-top: 20px" class="page-btn-right-top">
      <a-button type="primary" @click="goBack">关闭</a-button>
    </div>
  </base-breadcrumb>
</template>

<script>
  import { auditStatus} from '@/components/constant'
  import { getInvestigateType } from '@/api/subcontractors/subcontractors'
  import { getSubcontractorsList ,addSubcontractors ,editSubcontractors ,getSubDetails} from '@/api/subcontractors'
  import  {getUsersDetail,getAllBranchCompany} from '@/api/commons'
  import { getOrgsTree} from '@/api/subassembly/TreeSelectOrganization'
  import { getProject } from '@/api/themeChoose/themeChoose'
  const columns = [
    {
      title: '序号',
      width:65,
      scopedSlots: { customRender: 'serial' }
    },
    {
      title: '推荐分包商',
      dataIndex: 'recommendSubcontractors'
    },
    {
      title: '分包商类型',
      dataIndex: 'subcontractorTypes',
    },
    {
      title: '推荐人',
      dataIndex: 'recommend',
    },
    {
      title: '分公司',
      dataIndex: 'branchCompany',
    },
    {
      title: '推荐项目',
      dataIndex: 'recommendProject',
    },
    {
      title: '合作事项',
      dataIndex: 'cooperation',
    },
    {
      title: '状态 ',
      dataIndex: 'statusName',
    },
    {
      title: '操作',
      dataIndex: 'action',
      width: '150px',
      scopedSlots: { customRender: 'action' }
    }
  ]


  export default {
  name:'a'+Date.now(),
    components:{
    },
    props: {
      // 是否作为审批详情
      isAudit: {
        type: Boolean,
        default: false
      },
      // 是否作为意见征询
      isConsultation: {
        type: Boolean,
        default: false
      }
    },
    data(){
      this.columns = columns
      this.auditStatus = auditStatus
      return{    
        selectedRowKeys:'',
        selectedRows:'',
        disabled:false,
        invesList:[],
        projectList:[],
        confirmLoading:false,
        form:{
          list:[],
          list:[],
          recommendInfo:{
            recommendInfo:'',
            age:'',
            idNum:'',
            politicalFace:'',
            unitName:'',
            tel:'',
            position:'',
          }
        },
        value:'',
        title:'',
        companyList:[],
        visible:false,
        recommendInfo:{},
        advanced:false,
        total:{},
        userId:'',
        type:''
      }
    },
    computed: {
    },
    created(){
      this.userId = JSON.parse(sessionStorage.getItem('ycloud-user_info')).id
      this.id = this.$route.query.id
      this.type = this.$route.query.type
      if(this.isAudit){
        this.type = 'view';
      }
      this.handleSub(this.id,'view');
    },
    methods:{
      goBack() {
        if(this.type == 'approve' || this.isAudit){
          window.close()
        }else{
          this.$multiTab.close(this.$route.fullpath)
        }

      },
      getOrgsTree(){
        getAllBranchCompany({tagCodes:['BC']}).then(res=>{
          console.log(res.data)
            this.companyList=res.data
        })
      },
      changeBranchCompany(value){
        console.log(value)
        getProject({ branchComIds: [value] }).then(res=>{
          this.projectList = res.data
        })
      },

      getUsersDetail(){
        getUsersDetail({userId:this.userId}).then(res=>{
          this.form.recommendInfo.referrer = res.data.name
          this.form.recommendInfo.age = res.data.age
          this.form.recommendInfo.idNum = res.data.idCard
          this.form.recommendInfo.politicalFace = res.data.politicalFace
          const company = res.data.levels
          const lists = []
          company.forEach(item=>{
            lists.push(item.name)
          })
          this.form.recommendInfo.unitName = lists.join(",")
          this.form.recommendInfo.tel = res.data.phoneNum
          const arr = res.data.posts
          const list = []
          arr.forEach(item=>{
            list.push(item.name)
          })
          this.form.recommendInfo.position = list.join(",")
          this.recommendInfo = res.data
        })
      },
      getInvestigateType(){
        getInvestigateType({type:0}).then(res=>{
          this.invesList = res.data
        })
      },
      handleSub(id,type){
        this.getOrgsTree()
        this.visible = true
        this.title="查看分包商推荐"
        this.getInvestigateType()
        getSubDetails({id:id}).then(res=>{
          this.form = res.data
          let list = []
          this.form.list.forEach(item=>{
            list.push(item.id)
          })
          this.form.list = list
        })
        this.form.recommendInfo = this.recommendInfo
      },



    }
  }
</script>

<style scoped>
  .input{
    width:100%
  }
  .total{
    display:flex;
  }
  .total div{
    padding:0 5px
  }
  #selectbranch{
    width:30% !important
  }
</style>
